package candidate;

import com.dai.FlowableFirstApplication;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.*;
import org.flowable.idm.api.Group;
import org.flowable.idm.api.GroupQuery;
import org.flowable.idm.api.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@SpringBootTest(classes = FlowableFirstApplication.class)
@Slf4j
@RunWith(SpringRunner.class)
public class CandidataGroup {
    @Autowired
    private TaskService taskService;
    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private ProcessEngine processEngine;
    @Autowired
    private RepositoryService repositoryService;
    @Autowired
    private IdentityService identityService;//角色权限

    /**
     * @Title:test
     * @Description: 方法描述:候选人组
     */


    @Test
    public void test() {
        System.err.println("我拿到的流程引擎" + processEngine);
    }
// 用户管理
    @Test
    public void getUser(){
        User user = identityService.newUser("lisi");
        user.setEmail("lisi@qq.com");
        user.setFirstName("李");
        user.setLastName("四");
        user.setPassword("123456");
        identityService.saveUser(user);
    }

    //组
    @Test
    public void group() {
        Group group = identityService.newGroup("xjy");
        group.setType("2");
        group.setName("巡检员");
        identityService.saveGroup(group);
    }

    //用户和组关系的维护
    @Test
    public void addUserAndGroup() {
        Group group = identityService.createGroupQuery().groupName("巡检员").singleResult();
        Group group1 = identityService.createGroupQuery().groupName("检测员").singleResult();
        List<User> list = identityService.createUserQuery().list();
        for (User user : list) {
            if (user.getId().equals("lisi")){
                identityService.createMembership(user.getId(), group.getId());
            }
            if ("张三".equals(user.getId())){
                identityService.createMembership(user.getId(),group1.getId());
            }
        }
    }


}
